using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ChuanPlus.FormControl
{
    public partial class ControlReceipt : DevExpress.XtraEditors.XtraUserControl
    {
        Users currentUser;
        public ControlReceipt(Users currentUser)
        {
            InitializeComponent();
            comboSupplier.Properties.Items.AddRange(xpColSupplier);
            this.currentUser = currentUser;
        }

        private void ButtonSubmit_Click(object sender, EventArgs e)
        {
            if (validation())
            {
                Receipt re = new Receipt((Supplier)comboSupplier.SelectedItem, dateReceipt.DateTime, Convert.ToDouble(textAmount.Text), currentUser,"H");
                re.Save();
                xpColReceipt.Reload();
                reset();
                MessageBox.Show("New receipt has been created","Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
        public bool validation()
        {
            if (comboSupplier.Text == comboSupplier.Properties.NullText)
            { 
                MessageBox.Show("Please select supplier", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboSupplier.Focus();
                return false;
            }
            if (dateReceipt.Text == "")
            {
                MessageBox.Show("Please select receipt date", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateReceipt.Focus();
                return false;
            }
            if (textAmount.Text == "")
            {
                MessageBox.Show("Please enter amount", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textAmount.Focus();
                return false;
            }
            return true;
        }

        private void ButtonReset_Click(object sender, EventArgs e)
        {
            reset();
        }
        private void reset()
        {
            comboSupplier.Text = comboSupplier.Properties.NullText;
            dateReceipt.Text = "";
            textAmount.Text = "";
        }
    }
}
